﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using JY.IOC.Configuration.Enums;
using Microsoft.Extensions.DependencyInjection;

namespace JY.IOC.Configuration.Extensions
{
    /// <summary>
    /// 枚举转换扩展
    /// </summary>
    internal static class EnumExtension
    {
        #region # 转换ServiceLifetime —— static ServiceLifetime ToLifetime(this LifetimeMode?...
        /// <summary>
        /// 转换ServiceLifetime
        /// </summary>
        public static ServiceLifetime ToLifetime(this LifetimeMode? lifetimeMode)
        {
            ServiceLifetime serviceLifetime;

            if (lifetimeMode == LifetimeMode.PerCall)
            {
                serviceLifetime = ServiceLifetime.Transient;
            }
            else if (lifetimeMode == LifetimeMode.PerSession)
            {
                serviceLifetime = ServiceLifetime.Scoped;
            }
            else if (lifetimeMode == LifetimeMode.Singleton)
            {
                serviceLifetime = ServiceLifetime.Singleton;
            }
            else
            {
                serviceLifetime = ServiceLifetime.Transient;
            }

            return serviceLifetime;
        }
        #endregion
    }
}
